package com.ah.http.resttemplate;

import com.alibaba.fastjson.JSONException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;

import static com.ah.http.factory.HttpsFactory.https_post_rest_template_demo;


/**
 * @author Tao on 2020/8/5
 */
@RestController
public class HttpsSendController {

    @Resource(name = "skipVerifyRestTemplate")
    private RestTemplate skipVerifyRestTemplate;

//    @Resource(name = "verifyCaRestTemplate")
    private RestTemplate verifyCaRestTemplate;

    @Resource(name = "secondSkipRestTemplate")
    private RestTemplate secondSkipRestTemplate;

    /**
     * 跳过证书验证方式
     *
     * @return
     */
    @GetMapping("/skip")
    public String skipVerifyCert() throws JSONException {

        ResponseEntity responseEntity = https_post_rest_template_demo();
        return responseEntity.getBody().toString();
    }

    /**
     * 第二种跳过证书验证方式
     *
     * @return
     */
    @GetMapping("/secondskip")
    public String secondSkipVerifyCert() {
        ResponseEntity<String> forEntity = skipVerifyRestTemplate.getForEntity("https://192.168.30.223/api/getMenuList",
                String.class, new Object[]{});
        return forEntity.getBody();
    }

    /**
     * 根据证书验证
     *
     * @return
     */
    @GetMapping("/verify")
    public String verifyCert() {
        ResponseEntity<String> forEntity = verifyCaRestTemplate.getForEntity("https://192.168.30.223/api/getMenuList",
                String.class, new Object[]{});
        return forEntity.getBody();
    }

}
